<div xmlns:ext="http://www.extjs.com" class="body-wrap"><div class="inheritance res-block"><pre class="res-block-inner"><a href="output/Ext.data.Reader.html" ext:member="" ext:cls="Ext.data.Reader">Reader</a>
  <img src="resources/elbow-end.gif">JsonReader</pre></div><h1>Class <a href="source/JsonReader.html#cls-Ext.data.JsonReader">Ext.data.JsonReader</a></h1><table cellspacing="0"><tr><td class="label">Package:</td><td class="hd-info">Ext.data</td></tr><tr><td class="label">Defined In:</td><td class="hd-info"><a href="source/JsonReader.html#cls-Ext.data.JsonReader">JsonReader.js</a></td></tr><tr><td class="label">Class:</td><td class="hd-info"><a href="source/JsonReader.html#cls-Ext.data.JsonReader">JsonReader</a></td></tr><tr><td class="label">Subclasses:</td><td class="hd-info"><a href="output/Ext.data.ArrayReader.html" ext:cls="Ext.data.ArrayReader">ArrayReader</a></td></tr><tr><td class="label">Extends:</td><td class="hd-info"><a href="output/Ext.data.Reader.html" ext:cls="Ext.data.Reader" ext:member="">Reader</a></td></tr></table><div class="description"><p>The JSON Reader is used by a Proxy to read a server response that is sent back in JSON format. This usually
happens as a result of loading a Store - for example we might create something like this:</p>
<pre><code>Ext.regModel(<em>'User'</em>, {
    fields: [<em>'id'</em>, <em>'name'</em>, <em>'email'</em>]
});

<b>var</b> store = <b>new</b> Ext.data.Store({
    model: <em>'User'</em>,
    proxy: {
        type: <em>'ajax'</em>,
        url : <em>'users.json'</em>,
        reader: {
            type: <em>'json'</em>
        }
    }
});</code></pre>
<p>The example above creates a 'User' model. Models are explained in the <a href="output/Ext.data.Model.html" ext:cls="Ext.data.Model">Model</a> docs if you're
not already familiar with them.</p>
<p>We created the simplest type of JSON Reader possible by simply telling our <a href="output/Ext.data.Store.html" ext:cls="Ext.data.Store">Store</a>'s 
<a href="output/Ext.data.Proxy.html" ext:cls="Ext.data.Proxy">Proxy</a> that we want a JSON Reader. The Store automatically passes the configured model to the
Store, so it is as if we passed this instead:
<pre><code>reader: {
    type : <em>'json'</em>,
    model: <em>'User'</em>
}</code></pre>
<p>The reader we set up is ready to read data from our server - at the moment it will accept a response like this:</p>
<pre><code>[
    {
        <em>"id"</em>: 1,
        <em>"name"</em>: <em>"Ed Spencer"</em>,
        <em>"email"</em>: <em>"ed@sencha.com"</em>
    },
    {
        <em>"id"</em>: 2,
        <em>"name"</em>: <em>"Abe Elias"</em>,
        <em>"email"</em>: <em>"abe@sencha.com"</em>
    }
]</code></pre>
<p><u>Reading other JSON formats</u></p>
<p>If you already have your JSON format defined and it doesn't look quite like what we have above, you can usually
pass JsonReader a couple of configuration options to make it parse your format. For example, we can use the 
<a href="output/Ext.data.JsonReader.html#Ext.data.JsonReader-root" ext:member="root" ext:cls="Ext.data.JsonReader">root</a> configuration to parse data that comes back like this:</p>
<pre><code>{
    <em>"users"</em>: [
       {
           <em>"id"</em>: 1,
           <em>"name"</em>: <em>"Ed Spencer"</em>,
           <em>"email"</em>: <em>"ed@sencha.com"</em>
       },
       {
           <em>"id"</em>: 2,
           <em>"name"</em>: <em>"Abe Elias"</em>,
           <em>"email"</em>: <em>"abe@sencha.com"</em>
       }
    ]
}</code></pre>
<p>To parse this we just pass in a <a href="output/Ext.data.JsonReader.html#Ext.data.JsonReader-root" ext:member="root" ext:cls="Ext.data.JsonReader">root</a> configuration that matches the 'users' above:</p>
<pre><code>reader: {
    type: <em>'json'</em>,
    root: <em>'users'</em>
}</code></pre>
<p>Sometimes the JSON structure is even more complicated. Document databases like CouchDB often provide metadata
around each record inside a nested structure like this:</p>
<pre><code>{
    <em>"total"</em>: 122,
    <em>"offset"</em>: 0,
    <em>"users"</em>: [
        {
            <em>"id"</em>: <em>"ed-spencer-1"</em>,
            <em>"value"</em>: 1,
            <em>"user"</em>: {
                <em>"id"</em>: 1,
                <em>"name"</em>: <em>"Ed Spencer"</em>,
                <em>"email"</em>: <em>"ed@sencha.com"</em>
            }
        }
    ]
}</code></pre>
<p>In the case above the record data is nested an additional level inside the "users" array as each "user" item has
additional metadata surrounding it ('id' and 'value' in this case). To parse data out of each "user" item in the 
JSON above we need to specify the <a href="output/Ext.data.JsonReader.html#Ext.data.JsonReader-record" ext:member="record" ext:cls="Ext.data.JsonReader">record</a> configuration like this:</p>
<pre><code>reader: {
    type  : <em>'json'</em>,
    root  : <em>'users'</em>,
    record: <em>'user'</em>
}</code></pre>
<p><u>Response metadata</u></p>
<p>The server can return additional data in its response, such as the <a href="output/Ext.data.JsonReader.html#Ext.data.JsonReader-totalProperty" ext:member="totalProperty" ext:cls="Ext.data.JsonReader">total number of records</a> 
and the <a href="output/Ext.data.JsonReader.html#Ext.data.JsonReader-successProperty" ext:member="successProperty" ext:cls="Ext.data.JsonReader">success status of the response</a>. These are typically included in the JSON response
like this:</p>
<pre><code>{
    <em>"total"</em>: 100,
    <em>"success"</em>: true,
    <em>"users"</em>: [
        {
            <em>"id"</em>: 1,
            <em>"name"</em>: <em>"Ed Spencer"</em>,
            <em>"email"</em>: <em>"ed@sencha.com"</em>
        }
    ]
}</code></pre>
<p>If these properties are present in the JSON response they can be parsed out by the JsonReader and used by the
Store that loaded it. We can set up the names of these properties by specifying a final pair of configuration 
options:</p>
<pre><code>reader: {
    type : <em>'json'</em>,
    root : <em>'users'</em>,
    totalProperty  : <em>'total'</em>,
    successProperty: <em>'success'</em>
}</code></pre>
<p>These final options are not necessary to make the Reader work, but can be useful when the server needs to report
an error or if it needs to indicate that there is a lot of data available of which only a subset is currently being
returned.</p></div><div class="hr"></div><a id="Ext.data.JsonReader-configs"></a><h2>Config Options</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Config Options</th><th class="msource-header">Defined By</th></tr><tr class="config-row  inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-idProperty"></a><b><a href="source/Reader.html#cfg-Ext.data.Reader-idProperty">idProperty</a></b> : String<div class="mdesc">Name of the property within a row object
that contains a record identifier value.  Defaults to <tt>id</tt></div></td><td class="msource"><a href="output/Ext.data.Reader.html#idProperty" ext:member="#idProperty" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-implicitIncludes"></a><b><a href="source/Reader.html#cfg-Ext.data.Reader-implicitIncludes">implicitIncludes</a></b> : Boolean<div class="mdesc"><div class="short">True to automatically parse models nested within other models in a response
object. See the Ext.data.Reader intro doc...</div><div class="long">True to automatically parse models nested within other models in a response
object. See the Ext.data.Reader intro docs for full explanation. Defaults to true.</div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#implicitIncludes" ext:member="#implicitIncludes" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="config-row expandable "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.JsonReader-record"></a><b><a href="source/JsonReader.html#cfg-Ext.data.JsonReader-record">record</a></b> : String<div class="mdesc"><div class="short">The optional location within the JSON response that the record data itself can be found at.
See the JsonReader intro ...</div><div class="long">The optional location within the JSON response that the record data itself can be found at.
See the JsonReader intro docs for more details. This is not often needed and defaults to undefined.</div></div></td><td class="msource">JsonReader</td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-root"></a><b><a href="source/Reader.html#cfg-Ext.data.Reader-root">root</a></b> : String<div class="mdesc"><div class="short">Required.  The name of the property
which contains the Array of row objects.  Defaults to undefined.
An exception wil...</div><div class="long"><b>Required</b>.  The name of the property
which contains the Array of row objects.  Defaults to <tt>undefined</tt>.
An exception will be thrown if the root property is undefined. The data
packet value for this property should be an empty array to clear the data
or show no data.</div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#root" ext:member="#root" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-successProperty"></a><b><a href="source/Reader.html#cfg-Ext.data.Reader-successProperty">successProperty</a></b> : String<div class="mdesc"><div class="short">Name of the property from which to
retrieve the success attribute. Defaults to success.  See
Ext.data.DataProxy.excep...</div><div class="long">Name of the property from which to
retrieve the success attribute. Defaults to <tt>success</tt>.  See
<a href="output/Ext.data.DataProxy.html" ext:cls="Ext.data.DataProxy">Ext.data.DataProxy</a>.<a href="output/Ext.data.DataProxy.html#Ext.data.DataProxy-exception" ext:member="exception" ext:cls="Ext.data.DataProxy">exception</a>
for additional information.</div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#successProperty" ext:member="#successProperty" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-totalProperty"></a><b><a href="source/Reader.html#cfg-Ext.data.Reader-totalProperty">totalProperty</a></b> : String<div class="mdesc"><div class="short">Name of the property from which to
retrieve the total number of records in the dataset. This is only needed
if the wh...</div><div class="long">Name of the property from which to
retrieve the total number of records in the dataset. This is only needed
if the whole dataset is not passed in one go, but is being paged from
the remote server.  Defaults to <tt>total</tt>.</div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#totalProperty" ext:member="#totalProperty" ext:cls="Ext.data.Reader">Reader</a></td></tr></tbody></table><a id="Ext.data.JsonReader-props"></a><h2>Public Properties</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Property</th><th class="msource-header">Defined By</th></tr><tr class="property-row  "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.JsonReader-jsonData"></a><b><a href="source/JsonReader.html#prop-Ext.data.JsonReader-jsonData">jsonData</a></b> : Mixed<div class="mdesc">DEPRECATED - will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead</div></td><td class="msource">JsonReader</td></tr><tr class="property-row  inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-rawData"></a><b><a href="source/Reader.html#prop-Ext.data.Reader-rawData">rawData</a></b> : Mixed<div class="mdesc">The raw data object that was last passed to readRecords. Stored for further processing if needed</div></td><td class="msource"><a href="output/Ext.data.Reader.html#rawData" ext:member="#rawData" ext:cls="Ext.data.Reader">Reader</a></td></tr></tbody></table><a id="Ext.data.JsonReader-methods"></a><h2>Public Methods</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Method</th><th class="msource-header">Defined By</th></tr><tr class="method-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-getResponseData"></a><b class="method"><a href="source/Reader.html#method-Ext.data.Reader-getResponseData">getResponseData</a></b><span class="openparen">(&nbsp;</span><span title="Required" class="required">Object&nbsp;response</span><span class="closeparen">&nbsp;)</span><span class="colon">&nbsp;:&nbsp;</span><span class="return">Object</span><div class="mdesc"><div class="short">Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemen...</div><div class="long">Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemented by each subclass<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>response</code> : Object<div class="sub-desc">The responce object</div></li></ul><strong>Returns:</strong><ul><li><code>Object</code><div class="sub-desc">The useful data from the response</div></li></ul></div></div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#getResponseData" ext:member="#getResponseData" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="method-row expandable inherited"><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.Reader-read"></a><b class="method"><a href="source/Reader.html#method-Ext.data.Reader-read">read</a></b><span class="openparen">(&nbsp;</span><span title="Required" class="required">Object&nbsp;response</span><span class="closeparen">&nbsp;)</span><span class="colon">&nbsp;:&nbsp;</span><span class="return">Ext.data.ResultSet</span><div class="mdesc"><div class="short">Reads the given response object. This method normalizes the different types of response object that may be passed
to ...</div><div class="long">Reads the given response object. This method normalizes the different types of response object that may be passed
to it, before handing off the reading of records to the <a href="output/readRecords.html" ext:cls="readRecords">readRecords</a> function.<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>response</code> : Object<div class="sub-desc">The response object. This may be either an XMLHttpRequest object or a plain JS object</div></li></ul><strong>Returns:</strong><ul><li><code>Ext.data.ResultSet</code><div class="sub-desc">The parsed ResultSet object</div></li></ul></div></div></div></td><td class="msource"><a href="output/Ext.data.Reader.html#read" ext:member="#read" ext:cls="Ext.data.Reader">Reader</a></td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.data.JsonReader-readRecords"></a><b class="method"><a href="source/JsonReader.html#method-Ext.data.JsonReader-readRecords">readRecords</a></b><span class="openparen">(&nbsp;</span><span title="Required" class="required">Object&nbsp;data</span><span class="closeparen">&nbsp;)</span><span class="colon">&nbsp;:&nbsp;</span><span class="return">Ext.data.ResultSet</span><div class="mdesc"><div class="short">Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to
retrieve meta da...</div><div class="long">Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to
retrieve meta data from the response, and extractData to turn the JSON data into model instances.<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>data</code> : Object<div class="sub-desc">The raw JSON data</div></li></ul><strong>Returns:</strong><ul><li><code>Ext.data.ResultSet</code><div class="sub-desc">A ResultSet containing model instances and meta data about the results</div></li></ul></div></div></div></td><td class="msource">JsonReader</td></tr></tbody></table><a id="Ext.data.JsonReader-events"></a><h2>Public Events</h2><div class="no-members">This class has no public events.</div></div>